interface FormData {
  c_mk_dt: string;
  c_note: string;
  sc: any[];
  c_dname: string;
  md: string;
}

interface GoodsItem {
  c_gcode: string;
  c_name: string;
  c_qtty: number;
  [key: string]: any;
}

interface ConvertResult {
  c_userno: string;
  c_code: string;
  c_dt: string;
  c_data2: string; // 部门编码
  c_store_id: string; // 调出机构id
  c_sub_code: string; // 调出店仓库 
  c_id: string;
  c_pdano: string;  // 调入店仓库
  c_note: string;
  c_type: string;
}

export const convertDraft = (formData: FormData, goodsList: GoodsItem[], userNo: string,store_id:string) => {
  // 转换表单数据
  const baseData: ConvertResult = {
    c_userno: userNo,
    c_code: '',
    c_type: '店间调拨',
    c_dt: formData.c_mk_dt,
    c_data2: formData.c_dname, // 部门编码
    c_store_id: formData.md, // 调出机构id
    c_id: '1172', // 调入店ID
    c_sub_code: '本部', // 调出店仓库 
    c_pdano: '', // 调入店仓库
    c_note: formData.c_note || ''
  };

  // 转换商品数据
  const goodsData = goodsList.map(item => ({
    c_userno: userNo,
    c_store_id: formData.md,
    c_code: item.c_gcode || item.c_code,
    c_gname: item.c_name ||  item.c_gname,
    c_barcode: item.c_barcode || '',
    c_id: '1172', // 调入店ID
    c_sub_id: item.c_model || item.c_sub_id,
    c_qtty: Number(item.c_qtty || 0),
    c_qtty1: 0,
    c_qtty2: 0,
    c_amount: Number(item.c_price || 0),
    c_amount1: 0,
    c_note: '',
    c_type: '店间调拨',
    c_status: '初始',
    c_dt: formData.c_mk_dt || new Date().toISOString(),
    c_sub_code: '本部',
    c_pdano: '',
    c_data: item.c_barcode || item.c_data
  }));

  return {
    lstNew: [baseData, ...goodsData]
  };
};

// 使用示例:
/*
const formData = {
  c_mk_dt: '',
  c_note: '',
  sc: [],
  c_dname: '123',
  md: '1101'
};

const goodsList = [
  {
    c_gcode: '00332575',
    c_name: '老庙铂金',
    c_qtty: 2,
    // ...其他商品属性
  }
];

const result = convertDraft(formData, goodsList.slice(1), 'userNo');
*/ 